package com.sc.nft.admin.controller;


import cn.hutool.core.bean.BeanUtil;
import com.sc.nft.admin.request.*;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.EcologyCastConf;
import com.sc.nft.entity.EcologyCastExpendConf;
import com.sc.nft.entity.req.AdminEcologyIncomeConfButtonReq;
import com.sc.nft.entity.req.AdminEcologyIncomeConfRelevanceReq;
import com.sc.nft.entity.vo.ecology.*;
import com.sc.nft.service.AdminEcologyCastConfService;
import com.sc.nft.service.AdminEcologyNodeConfService;
import com.sc.nft.service.EcologyHatchIncomeConfRelevanceService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/ecology/node")
@Api(tags = "后台生态界定配置管理")
public class AdminEcologyNodeConfController {


    private final AdminEcologyNodeConfService adminEcologyNodeConfService;


    @PostMapping(value = "/getAdminIncomeConf", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取权益配置", notes = "获取权益配置", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<AdminEcologyIncomeConfRelevanceVO> getAdminIncomeConf(@Valid @RequestBody IdRequest idRequest) {
        return Result.success(adminEcologyNodeConfService.getAdminIncomeConf(idRequest.getId()));
    }

    @PostMapping(value = "/batchUpateIncomeScale", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "批量修改收益比例", notes = "批量修改收益比例", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result batchUpateIncomeScale(@Valid @RequestBody BatchUpateIncomeScaleRequest request) {
        adminEcologyNodeConfService.batchUpateIncomeScale(request.getList(),request.getId(),request.getHatchCollectionId());
        return Result.success();
    }



    @PostMapping(value = "/getNodeCollectionList", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取生态节点藏品", notes = "获取生态节点藏品", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<List<AdminNodeCollectionVO>> getNodeCollectionList(@RequestBody @Valid IdRequest idRequest) {
        return Result.success(adminEcologyNodeConfService.getNodeCollectionList(idRequest.getId()));
    }


    @PostMapping(value = "/addNodeCollection", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "添加生态节点藏品", notes = "获取生态节点藏品", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result addNodeCollection(@Valid @RequestBody AddEcologyNodeCollectionRequest request) {
        adminEcologyNodeConfService.addNodeCollection(request.getCollectionId(),request.getId());
        return Result.success();
    }


    @PostMapping(value = "/delNodeCollection", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "删除生态节点藏品", notes = "获取生态节点藏品", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result delNodeCollection(@Valid @RequestBody AddEcologyNodeCollectionRequest request) {
        adminEcologyNodeConfService.delNodeCollection(request.getCollectionId(),request.getId());
        return Result.success();
    }




    @PostMapping(value = "/ecologyRecycleRecords", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "生态熔炼-回收记录", notes = "生态熔炼-回收记录", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<AdminEcologyRecycleRecordsVO> ecologyRecycleRecords(@Valid @RequestBody EcologyRecycleRecordsRequest request) {
        return PageResult.success(adminEcologyNodeConfService.ecologyRecycleRecords(request.getCollectionName(),request.getNumbering(),request.getUserTel(),request.getType(),request.getBeginTime(),request.getEndTime(),request.toMp(),request.getCollectionStatus()));
    }




    @PostMapping(value = "/adminIncomeConfPage", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "平台权益配置列表", notes = "平台权益配置列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<AdminEcologyIncomeConfPageVO> adminIncomeConfPage(@RequestBody AdminIncomeConfPageRequest pageRequest) {
        return PageResult.success(adminEcologyNodeConfService.adminIncomeConfPage(pageRequest.getPageNo(),pageRequest.getPageSize(),pageRequest.getHatchCollectionId(),pageRequest.getIsOpen()));
    }


    @PostMapping(value = "/addIncomeScale", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "新增平台权益配置", notes = "新增平台权益配置", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result addIncomeScale(@Valid @RequestBody AdminEcologyIncomeConfRelevanceReq request) {
        adminEcologyNodeConfService.addIncomeScale(request.getList(),request.getHatchCollectionId(),request.getCollectionIdList());
        return Result.success();
    }



    @PostMapping(value = "/button", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "平台权益开关", notes = "平台权益开关", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result button(@Valid @RequestBody AdminEcologyIncomeConfButtonReq request) {
        adminEcologyNodeConfService.button(request.getId(),request.getStatus());
        return Result.success();
    }

    @PostMapping(value = "/remove", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "删除", notes = "删除", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result remove(@Valid @RequestBody IdRequest request) {
        adminEcologyNodeConfService.remove(request.getId());
        return Result.success();
    }

}
